package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {



    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    @Select("select * from setmeal where category_id = #{categoryId}")
    List<SetmealVO> getByCategoryId(SetmealDTO setmealDTO);

    @Select("select s.*,d.image,d.description from setmeal_dish s left outer join dish d " +
            "on s.dish_id = d.id " +
            "where s.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishesBySetmealId(Long setmealId);

    @Select("select * from setmeal where id = #{setmealId}")
    Setmeal getById(Long setmealId);


    @Update("update setmeal set status = 1 where id =#{id}")
    void enableDish(Integer id);

    @Update("update setmeal set status = 0 where id =#{id}")
    void disenableDish(Integer id);
}
